﻿using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace Elderos.Highlight.Search
{
    [DataContract]
    public class TextEntity
    {
        public TextEntity(int entityID, Position ownerPosition)
        {
            EntityID = entityID;
            OwnerPosition = ownerPosition;
        }

        [DataMember]
        public int EntityID { get; private set; }

        [DataMember]
        public double ResultCoef { get; set; }

        public Position OwnerPosition { get; set; }

        private List<FactorValue> _factorValues = new List<FactorValue>();
        [DataMember]
        public List<FactorValue> FactorValues
        {
            get { return _factorValues; }
            private set { _factorValues = value; }
        }

        public double[] FactorVector
        {
            get { return FactorValues.OrderBy(x => x.FactorName).Select(x => x.Weight).ToArray(); }
        }

        public override string ToString()
        {
            return EntityID + ": " + FactorValues.Count + " rules.";
        }
    }
}
